# -*- coding:utf-8 -*-
#
# Copyright © 2013 Lucian Smith

"""Tellurium Plugin to reskin the main application"""

import sys
import os

from spyderlib.qt.QtGui import (QWidget, QVBoxLayout)

# Local imports
from spyderlib.baseconfig import get_translation
_ = get_translation("p_tellurium_reset", dirname="spyderplugins")
from spyderlib.utils.qthelpers import get_icon
from spyderlib.plugins import SpyderPluginMixin
from spyderlib.baseconfig import DEV
from spyderlib import __version__

class TelluriumReset(QWidget, SpyderPluginMixin):
    """
    A plugin whose sole purpose in life is to reskin the main window.
    Anything that is irrelevant to the Tellurium app but is present
    in Spyder will be removed with this plugin.  Conversely, if you
    are interested in using Tellurium but do not want to change 
    the rest of Spyder's functionality, simply do not install this
    plugin.
    """
    CONF_SECTION = 'tellurium_reset'
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        SpyderPluginMixin.__init__(self, parent)
        layout = QVBoxLayout()
        self.setLayout(layout)
        
        # Initialize plugin
        self.initialize_plugin()
        
    #------ SpyderPluginWidget API --------------------------------------------
    def get_plugin_title(self):
        """Return widget title"""
        return _("TelluriumReset")
    
    def get_plugin_icon(self):
        """Return widget icon"""
        return None
    
    def get_focus_widget(self):
        """
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        """
        return None
    
    def get_plugin_actions(self):
        """Return a list of actions related to plugin"""
        # Font
        return []

    def on_first_registration(self):
        """Action to be performed on first plugin registration"""
        self.main.tabify_plugins(self.main.inspector, self)
        self.dockwidget.hide()

    def register_plugin(self):
        """Register plugin in Spyder's main window"""
        DEBUG = bool(os.environ.get('SPYDER_DEBUG', ''))
        title = "Spyder for Tellurium (%s; Python %s.%s)" % (__version__,
                                               sys.version_info[0],
                                               sys.version_info[1])
        if DEBUG:
            title += " [DEBUG MODE]"
        self.main.setWindowTitle(title)
        icon_name = 'Tellurium_light.ico' if self.main.light else 'Tellurium_filled_small.ico'
        # Resampling SVG icon only on non-Windows platforms (see Issue 1314):
        self.main.setWindowIcon(get_icon(icon_name, resample=os.name != 'nt'))
        self.main.add_dockwidget(self)
        #if self.main.extconsole is not None:
        #    from spyderlib.plugins.externalconsole import ExternalConsole
        #    self.main.extconsole.dockwidget.raise_()
        
        # Showing splash screen
        #Can't change the splash screen from a plugin
        #pixmap = QPixmap(get_image_path('Tellurium_splash.png'), 'png')
        #self.main.splash = QSplashScreen(pixmap)

    def refresh_plugin(self):
        """Refresh pylint widget"""
        pass
        
    def closing_plugin(self, cancelable=False):
        """Perform actions before parent main window is closed"""
        return True
            
    def apply_plugin_settings(self, options):
        """Apply configuration file's plugin settings"""
        pass
        
#==============================================================================
# The following statements are required to register this 3rd party plugin:
#==============================================================================
PLUGIN_CLASS = TelluriumReset

